<?php
	if ($_POST)
	{
		require('config.php');
        $pass = $_POST['password'];
        $id = $_POST['id'];
		$pass = md5($pass);
	    $stmt = $connection->prepare("select valid from user_forget_password where id=?");
	    $stmt->bind_param("s", $id);
	    $stmt->execute();
        $stmt->bind_result($valid);
        if ($stmt->fetch())
        {
            if ($valid == 1)
            {
                $stmt = $connection->stmt_init();
	            $stmt = $connection->prepare("delete from user_forget_password where id=?");
	            $stmt->bind_param("s", $id);
	            $stmt->execute();
                $stmt = $connection->stmt_init();
		        $stmt = $connection->prepare("update user_id_passwd set md5=?, cookie=0 where id=?");
	            $stmt->bind_param("ss", $pass, $id);
	            $stmt->execute();
                echo "success";
            }
            else
            {
                echo 'VALID IS 0';
            }
        }
        else
        {
            echo "NOVALID";
        }
    }
	else
	{
		echo "NOPOST";	
	}
?>
